package wap.dco.factory.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import wap.dco.Log;
import wap.dco.PcLog;
import wap.dco.WapLog;
import wap.dco.factory.ILogFactory;

public class LogFactoryImpl extends ILogFactory {

	private static final String wapLog = "\"(.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\",.*?\".*?)\"$";
	private static final String pvLog = "^.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?\t.*?$";

	private static Pattern p_wapLog = Pattern.compile(wapLog);
	private static Pattern p_pcLog = Pattern.compile(pvLog);

	@Override
	public Log createLog(String log) {
		Matcher matcher = p_wapLog.matcher(log);
		if (matcher.matches()) {
			return new WapLog(matcher.group(1));
		}
		matcher = p_pcLog.matcher(log);
		if (matcher.find()) {
			return new PcLog(matcher.group(0));
		}
		return null;
	}
}
